package com.wzf.greattruth.jvm.vola;

public class VolaliteTester {

    private static volatile int value;

    private static void inc() {
        value++;
    }

    public static void main(String[] args) {
        int threadCount = 10;
        final int times = 1000;

        Thread[] threads = new Thread[threadCount];
        for (int i = 0; i < threadCount; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0; j < times; j++) {
                        inc();
                    }
                }
            });
            threads[i] = thread;
            thread.start();
        }

        if (Thread.activeCount() > 1) {
            Thread.yield();
        }
        System.err.println("value=" + value);
    }
}
